* Project      :  The Full, Persistent, and Symmetric Pass-Through of a Temporary VAT Cut
* Authors      :  Márcia Silva-Pereira, João Quelhas, Tiago Bernardino, Ricardo Duque Gabriel
* Date         :  02/04/2025
* Description  :  Robustness - Control Groups
* Dependencies :
* Modifications: (add date, author and change)

** This file was created in order to have non-food products
** as these were excluded from the RESEARCH version of the database.

*********************************************************

* TABLE C.2: Robustness: Control Groups
*********************************************************

*********************************************************
*                 Construct the datasets                *
*********************************************************

// Initialize an empty dataset with the same structure as the data files.
quietly use "${path_source}/PI033_SDP_DPROD_202107_202401_AUCHAN_FEB24_POL.dta", clear

keep if _n == 0

// Generate a new variable to hold the supermarket name.
gen supermarket = ""

foreach store in "AUCHAN" "MINIPRECO" "PINGODOCE" {

 	use "${path_source}/PI033_SDP_DPROD_202107_202401_`store'_FEB24_POL.dta", clear

	summarize id, detail
	
	scalar id_median = r(p50)
	
	keep if id < id_median
	
	unskizpanel id date
	
	save "${path_work}/auxiliar/tempfile_2024_01_`store'_01.dta", replace
	
 	use "${path_source}/PI033_SDP_DPROD_202107_202401_`store'_FEB24_POL.dta", clear

	summarize id, detail
	
	scalar id_median = r(p50)
	
	keep if id >= id_median
	
	unskizpanel id date
	
	save "${path_work}/auxiliar/tempfile_2024_01_`store'_02.dta", replace
	
	use "${path_work}/auxiliar/tempfile_2024_01_`store'_01.dta", clear
	
	append using "${path_work}/auxiliar/tempfile_2024_01_`store'_02.dta", force
	
	tab date
	
	gen supermarket = "`store'"
	
	save "${path_work}/auxiliar/tempfile_2024_01_`store'.dta", replace
	
	erase "${path_work}/auxiliar/tempfile_2024_01_`store'_01.dta"
	erase "${path_work}/auxiliar/tempfile_2024_01_`store'_02.dta"
	
	}
	
foreach store in "CONTINENTE" {

 	use "${path_source}/PI033_SDP_DPROD_202109_202401_`store'_FEB24_POL.dta", clear

	summarize id, detail
	
	scalar id_median = r(p50)
	
	keep if id < id_median
	
	unskizpanel id date
	
	save "${path_work}/auxiliar/tempfile_2024_01_`store'_01.dta", replace
	
 	use "${path_source}/PI033_SDP_DPROD_202109_202401_`store'_FEB24_POL.dta", clear

	summarize id, detail
	
	scalar id_median = r(p50)
	
	keep if id >= id_median
	
	unskizpanel id date

	save "${path_work}/auxiliar/tempfile_2024_01_`store'_02.dta", replace
	
	use "${path_work}/auxiliar/tempfile_2024_01_`store'_01.dta", clear
	
	append using "${path_work}/auxiliar/tempfile_2024_01_`store'_02.dta", force
	
	tab date
	
	gen supermarket = "`store'"
	
	save "${path_work}/auxiliar/tempfile_2024_01_`store'.dta", replace

	erase "${path_work}/auxiliar/tempfile_2024_01_`store'_01.dta"
	erase "${path_work}/auxiliar/tempfile_2024_01_`store'_02.dta"

	}
	
foreach store in "AUCHAN" "MINIPRECO" "PINGODOCE" "CONTINENTE" {

 	use "${path_source}/PI033_SDP_DPROD_202402_`store'_MAR24_POL.dta", clear

	unskizpanel id date

	drop if date < td(01/02/2024)
	
	tab date
	
	gen supermarket = "`store'"
	
	save "${path_work}/auxiliar/tempfile_2024_02_`store'.dta", replace

	}

// Merge all temp files created for each supermarket.
use "${path_work}/auxiliar/tempfile_2024_01_AUCHAN.dta"
append using "${path_work}/auxiliar/tempfile_2024_01_CONTINENTE.dta", force
append using "${path_work}/auxiliar/tempfile_2024_01_MINIPRECO.dta", force
append using "${path_work}/auxiliar/tempfile_2024_01_PINGODOCE.dta", force

append using "${path_work}/auxiliar/tempfile_2024_02_AUCHAN.dta", force
append using "${path_work}/auxiliar/tempfile_2024_02_CONTINENTE.dta", force
append using "${path_work}/auxiliar/tempfile_2024_02_MINIPRECO.dta", force
append using "${path_work}/auxiliar/tempfile_2024_02_PINGODOCE.dta", force

erase "${path_work}/auxiliar/tempfile_2024_01_AUCHAN.dta"
erase "${path_work}/auxiliar/tempfile_2024_01_CONTINENTE.dta"
erase "${path_work}/auxiliar/tempfile_2024_01_MINIPRECO.dta"
erase "${path_work}/auxiliar/tempfile_2024_01_PINGODOCE.dta"

erase "${path_work}/auxiliar/tempfile_2024_02_AUCHAN.dta"
erase "${path_work}/auxiliar/tempfile_2024_02_CONTINENTE.dta"
erase "${path_work}/auxiliar/tempfile_2024_02_MINIPRECO.dta"
erase "${path_work}/auxiliar/tempfile_2024_02_PINGODOCE.dta"

// Sort the data.
sort id date

// Save the updated dataset used to work onwards.
keep  id name brand date supermarket price ean13 regular_price ppu ecoicop
order id ean13 date name brand supermarket price regular_price ppu ecoicop

keep if date >= td(01/01/2023)

save "${path_work}/auxiliar/working_dataset_policy.dta", replace

*********************************************************
*              Combine the two datasets                 *
*********************************************************

// Load the dataset named "working_dataset.dta" with a list of goods and zero VAT.
use "${path_work}/auxiliar/working_dataset_policy.dta", clear

// Merge the datasets based on the product ID and SUPERMARKET, using the "merged_zero_vat_list.dta".
merge m:1 id supermarket using "${path_work}/auxiliar/merged_zero_vat_list.dta"

// Drop rows where the merge resulted in no match (i.e., _merge == 2).
drop if _merge == 2

// Generate a variable 'treatment' based on the merge status (3 indicates a match).
gen treatment = _merge == 3

// Define labels for 'treatment' variable (0 as "control" and 1 as "treated").
label define lbl_treatment 0 "control" 1 "treated", replace

// Apply the defined labels to the 'treatment' variable.
label values treatment lbl_treatment

// Drop the merge status variable '_merge'.
drop _merge

// Group id and supermarket.
egen id_sm = group(id supermarket name)

// Set the data as a panel with daily observations.
xtset id_sm date, daily

// Save the updated dataset to a file named "combined_dataset.dta".
save "${path_work}/auxiliar/combined_dataset_policy.dta", replace

*********************************************************

erase "${path_work}/auxiliar/working_dataset_policy.dta"
erase "${path_work}/auxiliar/merged_zero_vat_list.dta"

*********************************************************


*********************************************************
*                   Clean the dataset                   *
*********************************************************

// Load the cleaned dataset.
use "${path_work}/auxiliar/combined_dataset_policy.dta", clear

// (1) Construction of relevant variables.

// Compute a price index with base in the day before policy announcement I.
local   base_date 23/03/2023
egen    base_price_23032023 = total(price / (date == td(`base_date'))), by(id_sm)
gen     index_23032023 = (price / base_price_23032023) * 100

// Compute a price index with base in the day before policy announcement II.
local   base_date 26/03/2023
egen    base_price_26032023 = total(price / (date == td(`base_date'))), by(id_sm)
gen     index_26032023 = (price / base_price_26032023) * 100

// Compute a price index with base in the day before policy implementation.
local   base_date 17/04/2023
egen    base_price_17042023 = total(price / (date == td(`base_date'))), by(id_sm)
gen     index_17042023 = (price / base_price_17042023) * 100

// Compute a price index with base in the day before the end of the policy.
local   base_date 04/01/2024
egen    base_price_04012024 = total(price / (date == td(`base_date'))), by(id_sm)
gen     index_04012024 = (price / base_price_04012024) * 100

// Identify treated and never treated IDs.
bys id_sm: egen treat	    = max(treatment)
gen             never_treat = (treat == 0)

// Rename variable ecoicop and identify the ECOICOP 4-digit classification.
rename ecoicop ecoicop5

// Identify products imported (0) and produced in Portugal (1).
gen domestic     = 1 if real(substr(string(ean13, "%14.0f"), 1, 3)) == 560
replace domestic = 0 if (real(substr(string(ean13, "%14.0f"), 1, 3)) != 560 & ean13 != .)

// Identify products from trademark-labels (0) and white-labels (1).
gen white_label = 0
foreach expr in "continente" "auchan" "pingo" "aldi" {
	replace white_label = 1 if strpos(brand, "`expr'") > 0
	}
	
// Identify products from small supermarkets (0) and big supermarkets (1).
gen big = 1 if supermarket == "CONTINENTE" | supermarket == "PINGODOCE"
replace big = 0 if big == .
	
// Identify products with price below average (0) and above average (1).
save "${path_work}/auxiliar/temp_file_non_food.dta", replace
keep if date >= td(01/01/2023) & date < td(01/03/2023)
egen average_price = mean(price), by(id_sm)
keep id_sm average_price
duplicates drop id_sm, force
save "${path_work}/auxiliar/average_price.dta", replace
use "${path_work}/auxiliar/temp_file_non_food.dta", clear
merge m:1 id_sm using "${path_work}/auxiliar/average_price.dta"
drop _merge
sum average_price, d
return list
gen high_price = 1 if average_price >= `r(mean)' 
replace high_price = 0 if average_price < `r(mean)'
erase "${path_work}/auxiliar/temp_file_non_food.dta"

*********************************************************

// (2) Flag products that were not certain to be treated (c.f. Portal das Finanças and Excel VAT_Doubts)

// Generate a new variable 'vat_doubt' and initialize it to missing values.
gen vat_doubt = .

// Loop through each product in the 'doubt' global list.
foreach expr in nabo couve carapau sangue meloa melancia sumo nectar vitelo vitela vitelao novilha novilho boi leitao bacalhau barrigas linguas cabecas caras abas galinha carcaca carcaça espetada espetadas hamburguer tostas panado panada nugget requeijao {
    // Set 'vat_doubt' to 1 for rows where the product name contains the current product in the loop.
    replace vat_doubt = 1 if strpos(name, "`expr'") > 0
}

// Loop through specific products to be flagged for further investigation.
foreach expr in "massa instantanea" "tomate seco" "tomate desidratado" "arroz vaporizado" "batata doce" "leite infantil" "leite crianca" "batata congelada" "cebola chalota" "ervilha torta" "manteiga alho" "manteiga ervas" "manteiga amendoim" "conserva atum tomate" "conserva atum escabeche" "conserva atum tomate" "conserva atum algarvia" "conserva atum picante" "conserva atum caldeirada" "conserva peixe" "mini tomate cherry" "arroz basmati" "arroz jasmim" "rolo de carne" {
    // Set 'vat_doubt' to 1 for rows where the product name contains the current product in the loop.
    replace vat_doubt = 1 if strpos(name, "`expr'") > 0
}

*********************************************************

// (4) Add usable time variable to the dataset and set it as a panel.

summarize id_sm, detail
scalar id_median = r(p50)	

save "${path_work}/auxiliar/temp_file_non_food.dta", replace

use "${path_work}/auxiliar/temp_file_non_food.dta", clear

keep if id_sm < id_median

// Merge datasets based on the 'date' variable using the "weeks.dta" file.
merge m:1 date using "${path_work}/source/weeks.dta"
drop if _merge == 2
drop _merge

save "${path_work}/auxiliar/temp_file_non_food_01.dta", replace

use "${path_work}/auxiliar/temp_file_non_food.dta", clear

keep if id_sm >= id_median

// Merge datasets based on the 'date' variable using the "weeks.dta" file.
merge m:1 date using "${path_work}/source/weeks.dta"
drop if _merge == 2
drop _merge

save "${path_work}/auxiliar/temp_file_non_food_02.dta", replace

use "${path_work}/auxiliar/temp_file_non_food_01.dta", clear
append using "${path_work}/auxiliar/temp_file_non_food_02.dta"

erase "${path_work}/auxiliar/temp_file_non_food_01.dta"
erase "${path_work}/auxiliar/temp_file_non_food_02.dta"
erase "${path_work}/auxiliar/temp_file_non_food.dta"

gen year = year(date)

// Generate a new variable 'week_year' representing the combination of year and week.
gen week_year = yw(year(date), week_number)

// Drop the original 'week' variable.
drop week_number

// Format 'week_year' as a Stata weekly date.
format week_year %tw

// Create a new variable 'month_year' representing the combination of year and month.
gen month_year = ym(year(date), month(date))

// Format 'month_year' as a Stata monthly date.
format month_year %tm

// Create a new variable 'day' with the day of the observation.
generate day = day(date)

// Set the data as a panel with daily observations.
xtset id_sm date, daily

// Save the updated dataset to a file named "cleaned_dataset.dta".
save "${path_work}/auxiliar/cleaned_dataset_policy.dta", replace

erase "${path_work}/auxiliar/combined_dataset_policy.dta"
erase "${path_work}/auxiliar/average_price.dta"

*********************************************************


* Create datasets used in baseline results and appendix.
*********************************************************

use "${path_work}/auxiliar/cleaned_dataset_policy.dta", clear

** (1) DATASET WITH NON-FOOD CONTROL

// Exclude observations before January 1, 2023.
keep if date >= td(01/01/2023)

// Exclude treated products that raised doubts.
drop if vat_doubt == 1

// Exclude treated products with a decrease of 23%.
drop if (treatment == 1 & ecoicop5 == "Óleos alimentares")

// Exclude outlier observations.
drop if supermarket == "PINGODOCE" & (day == 1 | day == 2 | day == 31 | day == 30 | day == 28 | day == 29 | day == 27)

// Exclude food items.
drop if (treatment == 0 & ecoicop5 !=  "Não é alimento nem bebida")

// Save the updated dataset to a file named "imputation_0.dta".
save "${path_work}/auxiliar/imputation_0_non_food.dta", replace

*********************************************************

** (2) DATASET WITH FOOD AND NON-FOOD CONTROL

use "${path_work}/auxiliar/cleaned_dataset_policy.dta", clear

// Exclude observations before January 1, 2023.
keep if date >= td(01/01/2023)

// Exclude treated products that raised doubts.
drop if vat_doubt == 1

// Exclude treated products with a decrease of 23%.
drop if (treatment == 1 & ecoicop5 == "Óleos alimentares")

// Exclude outlier observations.
drop if supermarket == "PINGODOCE" & (day == 1 | day == 2 | day == 31 | day == 30 | day == 28 | day == 29 | day == 27)

// Save the updated dataset to a file named "imputation_0.dta".
save "${path_work}/auxiliar/imputation_0_food_non_food_control.dta", replace

*********************************************************

erase "${path_work}/auxiliar/cleaned_dataset_policy.dta"

*********************************************************

*********************************************************
*                Event-study Regressions                *
*********************************************************

local vce_cluster ${vce_cluster}
local weights ${weights}
local variable ${variable}
local aggregation ${aggregation}

file open  myfile using "${results_tables}/table_c2.txt", write text replace
file write myfile "Robustness, Description, Implementation, Reversal" _n _n
file close myfile

*********************************************************


* All product as control
*********************************************************
	
// Load the cleaned dataset.
use "${path_work}/auxiliar/imputation_0_food_non_food_control.dta", clear

keep if date >= td(01/02/2023)
keep price ecoicop5 treatment id_sm five_day_number

collapse (${aggregation}) ${variable} (first) ecoicop5 treatment, by (id_sm five_day_number)

// Compute a price index with base in the day before policy announcement I.
local   base_date 22
egen    base_price_23032023 = total(${variable}/ (five_day_number == `base_date')), by(id_sm)
gen     index_23032023 = (${variable}/ base_price_23032023) * 100

xtset id_sm five_day_number

// Keep the data around the event.
keep if five_day_number >= 17
keep if five_day_number <= 32

// Policy variable: 1 after the reference date.
replace treatment = 0 if five_day_number < 23

// Run the event-study regression.
xtevent index_23032023, policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} ${window_high}) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)

matrix results = r(delta)
matrix vcv = r(Vdelta)

scalar coef_implementation = results[1,10]
scalar se_implementation   = sqrt(vcv[10,10])

// Load the cleaned dataset.
use "${path_work}/auxiliar/imputation_0_food_non_food_control.dta", clear

keep if date >= td(01/02/2023)
keep price ecoicop5 treatment id_sm five_day_number

collapse (${aggregation}) ${variable} (first) ecoicop5 treatment, by (id_sm five_day_number)

// Compute a price index with base in the day before policy announcement I.
local   base_date 22
egen    base_price_23032023 = total(${variable}/ (five_day_number == `base_date')), by(id_sm)
gen     index_23032023 = (${variable}/ base_price_23032023) * 100

xtset id_sm five_day_number

// Keep the data around the event.
keep if five_day_number >= 60
keep if five_day_number <= 83

// Policy variable: 1 after the reference date.
replace treatment = 0 if five_day_number < 66

// Run the event-study regression.
xtevent index_23032023, policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} 16) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
	
matrix results = r(delta)
matrix vcv = r(Vdelta)

scalar coef_reversal       = results[1,19]
scalar se_reversal         = sqrt(vcv[19,19])

file open  myfile using "${results_tables}/table_c2.txt", write text append

generate coeff_implementation = coef_implementation
generate see_implementation = se_implementation
generate coeff_reversal = coef_reversal
generate see_reversal = se_reversal

format %12.0g coeff_implementation see_implementation coeff_reversal see_reversal
file write myfile "1, All product as control, " (coeff_implementation) ", " (coeff_reversal) _n ", , (" (see_implementation) "), (" (see_reversal) ")" _n _n 
drop coeff_implementation see_implementation coeff_reversal see_reversal

file close myfile

erase "${path_work}/auxiliar/imputation_0_food_non_food_control.dta"

*********************************************************


* Only food products (incl. drinks)
*********************************************************

// Load the cleaned dataset.
use "${path_work}/auxiliar/imputation_0_all_products.dta", clear

collapse (${aggregation}) ${variable} (first) ecoicop5 treatment weight, by (id_sm five_day_number)

// Compute a price index with base in the day before policy announcement I.
local   base_date 22
egen    base_price_23032023 = total(${variable}/ (five_day_number == `base_date')), by(id_sm)
gen     index_23032023 = (${variable}/ base_price_23032023) * 100

xtset id_sm five_day_number

preserve

// Keep the data around the event.
keep if five_day_number >= 17
keep if five_day_number <= 32

// Policy variable: 1 after the reference date.
replace treatment = 0 if five_day_number < 23

if ${weights} == 0 {

// Run the event-study regression.
xtevent index_23032023, policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} ${window_high}) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
	
}

if ${weights} == 1 {

// Run the event-study regression.
xtevent index_23032023 [pweight = weight], policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} ${window_high}) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
		
}

matrix results = r(delta)
matrix vcv = r(Vdelta)

scalar coef_implementation = results[1,10]
scalar se_implementation   = sqrt(vcv[10,10])

restore

preserve

// Keep the data around the event.
keep if five_day_number >= 60
keep if five_day_number <= 83

// Policy variable: 1 after the reference date.
replace treatment = 0 if five_day_number < 66

if ${weights} == 0 {

// Run the event-study regression.
xtevent index_23032023, policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} 16) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
	
}

if ${weights} == 1 {

// Run the event-study regression.
xtevent index_23032023 [pweight = weight], policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} 16) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
		
}

matrix results = r(delta)
matrix vcv = r(Vdelta)

scalar coef_reversal       = results[1,19]
scalar se_reversal         = sqrt(vcv[19,19])

restore

file open  myfile using "${results_tables}/table_c2.txt", write text append

generate coeff_implementation = coef_implementation
generate see_implementation = se_implementation
generate coeff_reversal = coef_reversal
generate see_reversal = se_reversal

format %12.0g coeff_implementation see_implementation coeff_reversal see_reversal
file write myfile "2, Only food products (incl. drinks), " (coeff_implementation) ", " (coeff_reversal) _n ", , (" (see_implementation) "), (" (see_reversal) ")" _n _n
drop coeff_implementation see_implementation coeff_reversal see_reversal

file close myfile

erase "${path_work}/auxiliar/imputation_0_all_products.dta"

*********************************************************


* Only non-food products
*********************************************************
	
// Load the cleaned dataset.
use "${path_work}/auxiliar/imputation_0_non_food.dta", clear

collapse (${aggregation}) ${variable} (first) ecoicop5 treatment, by (id_sm five_day_number)

// Compute a price index with base in the day before policy announcement I.
local   base_date 22
egen    base_price_23032023 = total(${variable}/ (five_day_number == `base_date')), by(id_sm)
gen     index_23032023 = (${variable}/ base_price_23032023) * 100

xtset id_sm five_day_number

preserve

// Keep the data around the event.
keep if five_day_number >= 17
keep if five_day_number <= 32

// Policy variable: 1 after the reference date.
replace treatment = 0 if five_day_number < 23

// Run the event-study regression.
xtevent index_23032023, policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} ${window_high}) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)

matrix results = r(delta)
matrix vcv = r(Vdelta)

scalar coef_implementation = results[1,10]
scalar se_implementation   = sqrt(vcv[10,10])

restore

preserve

// Keep the data around the event.
keep if five_day_number >= 60
keep if five_day_number <= 83

// Policy variable: 1 after the reference date.
replace treatment = 0 if five_day_number < 66

// Run the event-study regression.
xtevent index_23032023, policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} 16) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
	
matrix results = r(delta)
matrix vcv = r(Vdelta)

scalar coef_reversal       = results[1,19]
scalar se_reversal         = sqrt(vcv[19,19])

restore

file open  myfile using "${results_tables}/table_c2.txt", write text append

generate coeff_implementation = coef_implementation
generate see_implementation = se_implementation
generate coeff_reversal = coef_reversal
generate see_reversal = se_reversal

format %12.0g coeff_implementation see_implementation coeff_reversal see_reversal
file write myfile "3, Only non-food products, " (coeff_implementation) ", " (coeff_reversal) _n ", , (" (see_implementation) "), (" (see_reversal) ")" _n _n 
drop coeff_implementation see_implementation coeff_reversal see_reversal

file close myfile

erase "${path_work}/auxiliar/imputation_0_non_food.dta"

*********************************************************


* Only products with a 6% VAT rate
*********************************************************
	
// Load the cleaned dataset.
use "${path_work}/auxiliar/imputation_0_reduced_tax_coicop.dta", clear

collapse (${aggregation}) ${variable} (first) ecoicop5 treatment weight, by (id_sm five_day_number)

// Compute a price index with base in the day before policy announcement I.
local   base_date 22
egen    base_price_23032023 = total(${variable}/ (five_day_number == `base_date')), by(id_sm)
gen     index_23032023 = (${variable}/ base_price_23032023) * 100

xtset id_sm five_day_number

preserve

// Keep the data around the event.
keep if five_day_number >= 17
keep if five_day_number <= 32

// Policy variable: 1 after the reference date.
replace treatment = 0 if five_day_number < 23

if ${weights} == 0 {

// Run the event-study regression.
xtevent index_23032023, policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} ${window_high}) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
	
}

if ${weights} == 1 {

// Run the event-study regression.
xtevent index_23032023 [pweight = weight], policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} ${window_high}) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
		
}

matrix results = r(delta)
matrix vcv = r(Vdelta)

scalar coef_implementation = results[1,10]
scalar se_implementation   = sqrt(vcv[10,10])

restore

preserve

// Keep the data around the event.
keep if five_day_number >= 60
keep if five_day_number <= 83

// Policy variable: 1 after the reference date.
replace treatment = 0 if five_day_number < 66

if ${weights} == 0 {

// Run the event-study regression.
xtevent index_23032023, policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} 16) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
	
}

if ${weights} == 1 {

// Run the event-study regression.
xtevent index_23032023 [pweight = weight], policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} 16) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
		
}

matrix results = r(delta)
matrix vcv = r(Vdelta)

scalar coef_reversal       = results[1,19]
scalar se_reversal         = sqrt(vcv[19,19])

restore

file open  myfile using "${results_tables}/table_c2.txt", write text append

generate coeff_implementation = coef_implementation
generate see_implementation = se_implementation
generate coeff_reversal = coef_reversal
generate see_reversal = se_reversal

format %12.0g coeff_implementation see_implementation coeff_reversal see_reversal
file write myfile "4, Only products with a 6% VAT rate, " (coeff_implementation) ", " (coeff_reversal) _n ", , (" (see_implementation) "), (" (see_reversal) ")" _n _n 
drop coeff_implementation see_implementation coeff_reversal see_reversal

file close myfile

erase "${path_work}/auxiliar/imputation_0_reduced_tax_coicop.dta"

*********************************************************
